package com.abc.robot01.activity

import android.os.Bundle
import android.util.Log
import android.widget.Toast
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.BasicText
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.lifecycleScope
import com.abc.robot01.R
import com.abc.robot01.activity.compose.Checkbox01
import com.abc.robot01.retrofit.bean.RenderQueueData
import com.abc.robot01.vivemodel.RenderViewModel
import com.abc.robot01.vivemodel.Robot
import com.bumptech.glide.integration.compose.ExperimentalGlideComposeApi
import com.bumptech.glide.integration.compose.GlideImage
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

/**
 * 渲染
 */
class RenderActivity : BaseVoiceActivity() {

    private val viewModel: RenderViewModel by viewModels()

    override fun onResume() {
        super.onResume()
        viewModel.started.value=false
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        viewModel.designPackageId.value = intent.getStringExtra("designPackageId")!!
        viewModel.housePlansDataId.value = intent.getStringExtra("housePlansDataId")!!
        viewModel.housePlansId.value = intent.getStringExtra("housePlansId")!!

//        viewModel.designPackageId.value = "ff808081898c82e8018991269ead080c"
//        viewModel.housePlansDataId.value = "2c90813f9343a933019347948cbb0054"
//        viewModel.housePlansId.value = "9978dd2e75934d4cbaab2c7360817e7e"

        lifecycleScope.launch {
            viewModel.load()
        }

        Log.e(TAG, "onCreate designPackageId "+   viewModel.designPackageId.value );
        Log.e(TAG, "onCreate housePlansDataId "+   viewModel.housePlansDataId.value );
        Log.e(TAG, "onCreate housePlansId "+   viewModel.housePlansId.value );


        setContent {
            val scrollState = rememberScrollState()
            MaterialTheme {
                Box {
                    Image(painter = painterResource(id = R.drawable.z1), contentDescription = "")
                    Row(modifier = Modifier.padding(30.px)) {
                        BackButton{
                            this@RenderActivity.finish()
                        }
                        Spacer(modifier = Modifier.width(82.px))
                        Column(modifier = Modifier
                            .fillMaxHeight()
                            .width(1400.px)) {
                            BasicText(
                                text = "渲染",
                                style = TextStyle(
                                    fontSize = 30.mysp,
                                    color = Color.Black,
                                    fontWeight = FontWeight.Bold
                                ),
                            )
                            Spacer(modifier = Modifier.height(30.px))
                            Column(
                                Modifier
                                    .verticalScroll(scrollState)
                                    .fillMaxSize(),
                                verticalArrangement = Arrangement.spacedBy(30.px)
                            ) {
                                Title1()
                                Title2()
                                Content3("渲染费用")
                                Content4("支付方式")
                                Spacer(modifier = Modifier.height(50.dp))
                            }
                        }
                    }
                    CenteredRowDemo()
                }
            }
        }
        Log.e(TAG, "onCreate");
    }

    @Composable
    fun Title1() {
        Title(title = "用户信息") {
            Row(verticalAlignment = Alignment.CenterVertically) {
                BasicText(
                    text = "用户名称",
                    style = TextStyle(
                        fontSize = 26.mysp,
                        color = MYBLACK
                    ),
                )
                Spacer(modifier = Modifier.width(20.px))
                val name = remember {  viewModel.customerName}
                CustomStyledTextField2(name, textColor = MYBLACK_Percent5)

                Spacer(modifier = Modifier.width(60.px))
                BasicText(
                    text = "手机号",
                    style = TextStyle(
                        fontSize = 26.mysp,
                        color = MYBLACK
                    ),
                )
                Spacer(modifier = Modifier.width(20.px))
                val phone = remember { viewModel.customerPhone }
                CustomStyledTextField2(
                    text=phone,
                    textColor = MYBLACK_Percent5,
                    keyboardOptions = KeyboardOptions.Default.copy(keyboardType = KeyboardType.Number))
            }
        }
    }

    /**
     *  渲染设置
     */
    @OptIn(ExperimentalGlideComposeApi::class)
    @Composable
    fun Title2() {
        Title(title = "渲染设置") {
            Row(verticalAlignment = Alignment.CenterVertically) {
                // 红色的星号，表示必填
                Text(
                    text = "*",
                    color = Color.Red,
                    fontSize = 7.sp, // 可以根据需要调整字体大小
                )

                BasicText(
                    text = "渲染名称",
                    style = TextStyle(
                        fontSize = 26.mysp,
                        color = Color(0xFF000000)
                    ),
                )
                Spacer(modifier = Modifier.width(20.px))
                val name = remember { viewModel.houseName }
                CustomStyledTextField2(name, textColor = MYBLACK_Percent5)
            }

            Row(
                verticalAlignment = Alignment.CenterVertically, modifier = Modifier
                    .padding(start = 48.px, end = 108.px)
                    .background(Color.Transparent)
            ) {
                // 红色的星号，表示必填
                Row(verticalAlignment = Alignment.CenterVertically) {
                    Text(
                        text = "*",
                        color = Color.Red,
                        fontSize = 7.sp, // 可以根据需要调整字体大小
                    )
                    BasicText(
                        text = "空间",
                        style = TextStyle(
                            fontSize = 26.mysp,
                            color = Color(0xFF000000)
                        ),
                    )
                }
                Spacer(modifier = Modifier.width(20.px))
                Space()
            }

            Spacer(modifier = Modifier.height(30.px))

            //氛围外景 开始
            Row(verticalAlignment = Alignment.CenterVertically) {
                // 红色的星号，表示必填
                Text(
                    text = "*",
                    color = Color.Red,
                    fontSize = 7.sp, // 可以根据需要调整字体大小
                )

                BasicText(
                    text = "氛围外景",
                    style = TextStyle(
                        fontSize = 26.mysp,
                        color = Color(0xFF000000)
                    ),
                )
                Spacer(modifier = Modifier.width(20.px))

                Column {
                    val radioOptions by viewModel.skyBoxList.collectAsState()
                    val selectedOption  =  remember { viewModel.selectedSkyBoxName }
                        Row(horizontalArrangement = Arrangement.spacedBy(20.px)) {
                            radioOptions.forEach {
                                Column(horizontalAlignment = Alignment.CenterHorizontally) {
                                    GlideImage(
                                        model = it.imgUrl.trim(),
                                        contentDescription ="",
                                        modifier = Modifier.size(192.px, 108.px)
                                    )
                                    Spacer(modifier = Modifier.height(10.px))
                                    CustomRadioButtonDemo2(it.name, selectedOption)
                                }
                            }
                        }
                }
            }   //氛围外景 结束

            Spacer(modifier = Modifier.height(30.px))

        //渲染方式 开始
        Row(verticalAlignment = Alignment.CenterVertically) {
            // 红色的星号，表示必填
            Text(
                text = "*",
                color = Color.Red,
                fontSize = 7.sp, // 可以根据需要调整字体大小
            )

            BasicText(
                text = "渲染方式",
                style = TextStyle(
                    fontSize = 26.mysp,
                    color = Color(0xFF000000)
                ),
            )
            Spacer(modifier = Modifier.width(20.px))
                CustomRadioButtonDemo()
            Spacer(modifier = Modifier.width(10.px))
//            BasicText(
//                text = "白天时间段08:30 - 22:59，默认日间渲染，其他时间段屏蔽日间渲染",
//                style = TextStyle(
//                    fontSize = 20.mysp,
//                    color = Color(0xFFFB870C)
//                ),
//            )
        }   //渲染方式 结束
            More()
    }
}
    /**
     *  还有多少人
     */
    @Composable
    fun More(){
        val more by remember { viewModel.more }
        val selectedIndex by remember { viewModel.selectedIndex }
        val radioOptions: List<RenderQueueData> by viewModel.modeList.collectAsState()
        Row(verticalAlignment = Alignment.CenterVertically) {
            Spacer(modifier = Modifier.width(128.px))
            Card(
                colors = CardDefaults.cardColors().copy(containerColor = MYBLACK_Percent5),
                modifier= Modifier
                    .padding(0.dp)
                    .size(1134.px, 60.px)
                ,shape= RoundedCornerShape(10.px)
            ) {
                Spacer(modifier = Modifier.height(20.px))
                Row {
                    Spacer(modifier = Modifier.width(20.px))
                    //如果是白天
                    if ( (viewModel.day.value && (selectedIndex == 0 || selectedIndex == 1 ))
                        ||   (viewModel.day.value.not()  && selectedIndex == 0 ))
                        {
                        BasicText(
                            text = "前面还有",
                            style = TextStyle(
                                fontSize = 20.mysp,
                                color = MYBLACK,
                            )
                        )
                    BasicText(
                        text = more,
                        style = TextStyle(
                            fontSize = 20.mysp,
                            color = Color.Red,
                        )
                    )
                    BasicText(
                        text = "人等待渲染",
                        style = TextStyle(
                            fontSize = 20.mysp,
                            color = MYBLACK,
                        )
                    )
                }
                    if ( (viewModel.day.value && selectedIndex == 1)
                        ||
                        (viewModel.day.value.not() && selectedIndex == 0)
                        ) {
                        Spacer(modifier = Modifier.width(40.px))
                        BasicText(
                            text = "夜间渲染",
                            style = TextStyle(
                                fontSize = 20.mysp,
                                color = MYBLACK,
                            )
                        )
                        Spacer(modifier = Modifier.width(10.px))

                        BasicText(
                            text = "当日22:00 - 次日08:30分之间渲染，价格*0.5",
                            style = TextStyle(
                                fontSize = 20.mysp,
                                color = MYBLACK_Percent60,
                            )
                        )
                    }
                    if ((viewModel.day.value && selectedIndex == 2)
                    || viewModel.day.value.not() && selectedIndex == 1)
                    {
//                        Spacer(modifier = Modifier.width(20.px))
                        BasicText(
                            text = "加急渲染",
                            style = TextStyle(
                                fontSize = 20.mysp,
                                color = MYBLACK,
                            )
                        )
                        Spacer(modifier = Modifier.width(10.px))
                        BasicText(
                            text = "优先开始渲染，价格*1.5",
                            style = TextStyle(
                                fontSize = 20.mysp,
                                color = MYBLACK_Percent60,
                            )
                        )
                    }
                }
            }
        }
    }

    /**
     *  渲染费用
     */
    @Composable
    fun Content3(title:String) {
        Title(title = title) {
            Row(verticalAlignment = Alignment.CenterVertically) {
                // 红色的星号，表示必填
//                Text(
//                    text = "*",
//                    color = Color.Red,
//                    fontSize = 7.sp, // 可以根据需要调整字体大小
//                )

                BasicText(
                    text = "渲染空间",
                    style = TextStyle(
                        fontSize = 26.mysp,
                        color = Color(0xFF000000)
                    ),
                )
                Spacer(modifier = Modifier.width(20.px))


                val total by remember {  viewModel.totalQuantity }

                Box(
                    modifier = Modifier
                        .size(200.px, 50.px)
                        .background(MYBLACK_Percent5) // 设置背景色
                ) {
                    BasicText(
                        modifier = Modifier.align(Alignment.Center), // 左对齐
                        text = "${total}",
                        style = TextStyle(
                            fontSize = 26.mysp,
                            color = MYBLACK_Percent60
                        )
                    )
                }

//                BasicText(
//                    text = total.value+"张",
//                    style = TextStyle(
//                        fontSize = 26.mysp,
//                        color = Color(0xFF000000)
//                    ),
//                )
//                CustomStyledTextField3(last = "张",text = name, textColor = Color(0xff000000))

                Spacer(modifier = Modifier.width(40.px))

                // 红色的星号，表示必填
//                Text(
//                    text = "*",
//                    color = Color.Red,
//                    fontSize = 7.sp, // 可以根据需要调整字体大小
//                )

                BasicText(
                    text = "渲染费用",
                    style = TextStyle(
                        fontSize = 26.mysp,
                        color = Color(0xFF000000)
                    ),
                )
                Spacer(modifier = Modifier.width(20.px))
                val totalAmount by remember {  viewModel.totalAmount}
                Box(
                    modifier = Modifier
                        .size(200.px, 50.px)
                        .background(MYBLACK_Percent5) // 设置背景色
                        .padding(top = 10.px, bottom = 10.px, start = 20.px, end = 20.px) // 设置内边距
                ) {
                     BasicText(
                         modifier = Modifier.align(Alignment.CenterStart), // 左对齐
                         text = "${totalAmount}",
                         style = TextStyle(
                             fontSize = 26.mysp,
                             color = MYBLACK_Percent60
                         )
                     )
                     BasicText(
                         modifier = Modifier.align(Alignment.CenterEnd), // 右对齐
                         text = "元",
                         style = TextStyle(
                             fontSize = 26.mysp,
                             color = MYBLACK_Percent60
                         )
                     )
                 }
//                }


//                BasicText(
//                    text = totalAmount.value+"元",
//                    style = TextStyle(
//                        fontSize = 26.mysp,
//                        color = Color(0xFF000000)
//                    ),
//                )
//                CustomStyledTextField3(last = "元",text = name2, textColor = Color(0xff000000))
            }
            Row(
                verticalAlignment = Alignment.Top, modifier = Modifier
                    .padding(start = 48.px, end = 108.px)
                    .background(Color.Transparent)
            ) {
            }
            Spacer(modifier = Modifier.height(30.px))
        }
    }

    /**
     *  渲染费用
     */
    @Composable
    fun Content4(title:String) {
        Title(title = title) {
            Row(verticalAlignment = Alignment.CenterVertically) {
                // 红色的星号，表示必填
                Text(
                    text = "*",
                    color = Color.Red,
                    fontSize = 7.sp, // 可以根据需要调整字体大小
                )

                BasicText(
                    text = "支付方式",
                    style = TextStyle(
                        fontSize = 26.mysp,
                        color = Color(0xFF000000)
                    ),
                )
                Spacer(modifier = Modifier.width(20.px))
                //支付方式
                CustomRadioButtonDemo2()
            }
            Row(
                verticalAlignment = Alignment.Top, modifier = Modifier
                    .padding(start = 48.px, end = 108.px)
                    .background(Color.Transparent)
            ) {
            }
            Spacer(modifier = Modifier.height(30.px))
        }
    }

    /**
     *  支付方式
     */
    @Composable
    fun CustomRadioButtonDemo2() {
        var paymentMethod by remember { viewModel.paymentMethod } // 默认选中第一个选项
        Row(
                verticalAlignment = Alignment.CenterVertically,
                horizontalArrangement = Arrangement.spacedBy(20.px)
            ) {


            Row(verticalAlignment = Alignment.CenterVertically) {
                CustomRadioButton(
                    selected =  paymentMethod == 1,
                    onClick = {
                        paymentMethod = 1
                    },
//                    size = 30.px // 自定义 RadioButton 的尺寸
                )
                Spacer(modifier = Modifier.width((10.px)))
                BasicText(
                    text = "帐户支付",
                    style = TextStyle(
                        fontSize = 26.mysp,
                        color = Color(0xFF000000)
                    ),
                )
            }

            Spacer(modifier = Modifier.width((30.px)))
            val amount by remember { viewModel.amount }
            Box(
                modifier = Modifier
                    .background(MYBLACK_Percent5) // 设置背景色
                    .padding(top = 10.px, bottom = 10.px, start = 20.px, end = 20.px) // 设置内边距
            ) {
                BasicText(
                    text = "账户余额：¥${amount}元",
                    style = TextStyle(
                        fontSize = 26.mysp,
                        color = MYBLACK_Percent60
                    )
                )
            }
            Spacer(modifier = Modifier.width((200.px)))
                    Row(verticalAlignment = Alignment.CenterVertically) {
                        CustomRadioButton(
                            selected =  paymentMethod == 2,
                            onClick = {
                                paymentMethod = 2
                            },
                        )
                        Spacer(modifier = Modifier.width((10.px)))
                        BasicText(
                            text = "扫码支付",
                            style = TextStyle(
                                fontSize = 26.mysp,
                                color = Color(0xFF000000)
                            ),
                        )
                    }







            }
    }

    /**
     *  渲染方式  价格系数
     */
    @Composable
    fun CustomRadioButtonDemo() {
        val radioOptions: List<RenderQueueData> by viewModel.modeList.collectAsState()
        var  radioOptions2 = radioOptions

//        if(viewModel.day.value.not() &&
                 //如果是夜间
        if(radioOptions2.isEmpty().not() && viewModel.isWithinDaytime().not()) {
            radioOptions2 = radioOptions2.drop(1)
        }

        if(radioOptions2.isNotEmpty()) {
            var selectedOption by remember { mutableStateOf(radioOptions[0]) } // 默认选中第一个选项
            Row(
                verticalAlignment = Alignment.CenterVertically,
                horizontalArrangement = Arrangement.spacedBy(20.px)
            ) {
                radioOptions2.forEachIndexed() { index,option ->
                    Row(verticalAlignment = Alignment.CenterVertically) {
                        CustomRadioButton(
                            selected = selectedOption == option,
                            onClick = {
                                selectedOption = option
                                viewModel.selectedOption.value = option.name
                                viewModel.selectedIndex.value = index
                              val a  =  radioOptions.find { it.name ==   viewModel.selectedOption.value }
                                a?.let {
                                    Log.e(TAG, "获取渲染价格配置: "+a.name)
                                    Log.e(TAG, "获取渲染价格配置: "+a.ratio)
                                    viewModel.totalAmount.value =  viewModel.getTotal(viewModel.houseTypeList.value).also {
                                        Log.e(TAG, "总价格: "+it)
                                    }
                                }
                                      },
                        )
                        Spacer(modifier = Modifier.width((10.px)))
                        BasicText(
                            text = option.name,
                            style = TextStyle(
                                fontSize = 26.mysp,
                                color = Color(0xFF000000)
                            ),
                        )
                    }
                }
            }
        }
    }

    @Composable
    fun BoxScope.CenteredRowDemo() {
        val totalAmount by remember { viewModel.totalAmount}
        Row(
            modifier = Modifier
                .align(Alignment.BottomCenter)
                .fillMaxWidth()
                .height(74.px) // 设置行的高度为100dp
                .background(Color.White),
            verticalAlignment = Alignment.CenterVertically // 设置垂直居中
        ) {
            Spacer(modifier = Modifier.weight(100f))
            Row(verticalAlignment=Alignment.Bottom) {
                BasicText(
                    text = "应付合计",
                    style = TextStyle(
                        fontSize = MyFont_Size,
                        color = Color.Black,
                        textAlign = TextAlign.Center,
                    ),
                )
                Spacer(modifier = Modifier.width(20.px))
                BasicText(
                    text = "¥",
                    style = TextStyle(
                        fontSize = 20.mysp,
                        color = Color.Blue,
                        textAlign = TextAlign.Center,
                        fontWeight = FontWeight.Bold
                    ),
                )
                BasicText(
                    text = totalAmount,
                    style = TextStyle(
                        fontSize = 38.mysp,
                        color = Color.Blue,
                        textAlign = TextAlign.Center,
                        fontWeight = FontWeight.Bold
                    ),
                )
                BasicText(
                    text = "元",
                    style = TextStyle(
                        fontSize = 20.mysp,
                        color = Color.Blue,
                        textAlign = TextAlign.Center,
                    ),
                )
            }

            Spacer(modifier = Modifier.width(100.px))
            MyButton01(text = "取消",textColor = Color.Black){
                finish()
            }
            Spacer(modifier = Modifier.width(20.px))
            MyButton01(text = "支付渲染",
                containerColor= MYBLUE,
                textColor = Color.White){
                    submit()
            }
            Spacer(modifier = Modifier.width(30.px))
        }
    }

    /**
     *   定义一个title ,下面是内容 ,
     *   例子可以查看: https://www.figma.com/design/7YtLSgj000mxvLmuyPJynl/%E4%B8%80%E6%9D%9F%E5%85%89%E7%A7%91%E6%8A%80--%E6%9C%BA%E5%99%A8%E4%BA%BA%E7%AB%AF?node-id=385-11603&node-type=CANVAS&t=K4gI0sJdooGo8tU4-0
     */
    @Composable
    fun Title(title:String="用户信息",content: @Composable ColumnScope.() -> Unit) {
            Card(
                colors = androidx.compose.material3.CardDefaults.cardColors(
                    containerColor = Color.White // 设置背景色为白色
                ),
                modifier = Modifier
                    .width(1400.px)
//                    .heightIn(min = 90.px)
                    .background(Color.Transparent),
                shape = RoundedCornerShape(20.px
                )
            ) {
                Column(modifier = Modifier
                    .padding(start = 30.px,top=30.px, bottom = 30.px)) {
                    Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier
                        .background(Color.Transparent)
                        .clickable {
                        }) {
                        BasicText(
                            text = title,
                            style = TextStyle(
                                fontSize = MyFont_Size,
                                color = Color.Black,
                                fontWeight = FontWeight.Bold
                            ),
                        )
                    }
                        Spacer(modifier = Modifier.height(30.px))
                    content()
                }
            }
        }



    private fun submit(){
        if(viewModel.houseName.value.trim() == ""){
            Toast.makeText(this@RenderActivity, "请填写渲染名称", Toast.LENGTH_LONG).show()
            return
        }
        if(viewModel.customerName.value.trim() == ""){
            Toast.makeText(this@RenderActivity, "请填写用户名称", Toast.LENGTH_LONG).show()
            return
        }
        if(viewModel.customerPhone.value.trim() == ""){
            Toast.makeText(this@RenderActivity, "请填写手机号", Toast.LENGTH_LONG).show()
            return
        }
        if(viewModel.totalQuantity.value.trim() == "0"){
            Toast.makeText(this@RenderActivity, "请至少选择一个空间", Toast.LENGTH_LONG).show()
            return
        }

        viewModel.submit()
        if(viewModel.started.value) return
        viewModel.started.value=true
        startActivity<ZhifuActivity>(){
            val renderRoomIds = viewModel.houseTypeList.value.filter { it.selected }
                .joinToString(",") { it.id }
            Log.e(TAG, "renderRoomIds: "+renderRoomIds)
            val sky =  viewModel.skyBoxList.value.find { it.name == viewModel.selectedSkyBoxName.value }!!.skyBoxId
            putExtra("skyBoxId",sky)
            putExtra("renderRoomIds",renderRoomIds)
            putExtra("userName",viewModel.customerName.value)
            putExtra("paymentMethod",viewModel.paymentMethod.value)
            putExtra("name",viewModel.houseName.value)
            putExtra("customerPhone",viewModel.customerPhone.value)
            putExtra("designPackageId",viewModel.designPackageId.value)
            putExtra("housePlansId",viewModel.housePlansId.value)
            putExtra("housePlansDataId",viewModel.housePlansDataId.value)
            putExtra("fee",viewModel.totalAmount.value)
        }
    }

    companion object {
        val TAG = "XuanRanActivity"
    }

    /**
     * 空间
     */
    @Composable
    fun Space() {
        var items by remember { viewModel.houseTypeList
        }

        // Group items into chunks of 6
        val groupedItems = items.chunked(9)

        Column(modifier = Modifier.fillMaxSize()) {
            // Iterate through each group and create a Row for each
            for (group in groupedItems) {
                Row(modifier = Modifier, horizontalArrangement = Arrangement.SpaceBetween) {
                    for (item in group) {
                        Checkbox01(
                            modifier = Modifier
                                .size(30.px),
                            checked = item.selected,
                            onCheckedChange = { it2 ->
                                Log.e(TAG, "onCheckedChange: "+ it2)
                                items = items.map {
                                    if (it.id == item.id) it.copy(selected = it2) else it
                                }.toMutableList()

                                viewModel.totalQuantity.value = items.filter { it.selected }.size.toString()
                                viewModel.totalAmount.value =  viewModel.getTotal(items)
                                Log.e(TAG, "总费用: "+  viewModel.totalAmount.value)
                            }
                        )
                        BasicText(
                            modifier = Modifier.offset(x = 0.dp),
                            text = item.name,
                            style = TextStyle(
                                fontSize = MyFont_Size,
                                color = Color(0xFF000000)
                            ),
                        )
                        Spacer(modifier = Modifier.width(30.px))
                    }
                }
            }
        }
        }
}
